<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text">
  <div></div>
  <button>猜字谜</button>
  <script>
    let int = document.querySelector('input')
    let button = document.querySelector('button')
    let xhr = new XMLHttpRequest()
    xhr.open('get', 'https://apis.tianapi.com/zimi/index?key=f91ff265d7a7bbed6de9d34babf5abcf')
    xhr.send()
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4 && xhr.status == 200) {
        console.log(xhr.responseText);

        let xml = JSON.parse(xhr.responseText).result.content
        // document.querySelector('div').innerHTML = xml
        alert(xml)
        button.onclick = function () {
          if (int.value == JSON.parse(xhr.responseText).result.answer) {
            alert(JSON.parse(xhr.responseText).result.reason)
          }
          else {
            alert('不对')
          }
        }
      }
    }
  </script>
</body>

</html>